//
//  SubTopicViewcontroller.m
//  TipsProject
//
//  Created by Suny on 15/5/19.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import "SubTopicViewcontroller.h"
#import "TopicInfo.h"
#import "AddTitpTittleViewController.h"
#import "TipAbstractListViewController.h"

@implementation SubTopicViewcontroller
- (void)viewDidLoad
{
	[super viewDidLoad];

    if (!self.viewForSearch)
    {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(handleShowSubTopicNotification:)
                                                     name:@"kShowSubTopicNotification"
                                                   object:nil];
		
    }
    else
    {
		
		self.navigationItem.leftBarButtonItem =  self.defaultBackButtonItem;

		
        [self reloadTableView];
    }
	self.view.backgroundColor = [UIColor colorWithHexString:@"ebebeb"];
	self.tableView.backgroundColor = [UIColor colorWithHexString:@"ebebeb"];

//	self.tableView.left = 200;
}

- (void)handleShowSubTopicNotification:(NSNotification *)notification
{
	NSArray *array = [notification object];
	if (CHECK_VALID_ARRAY(array))
	{
		self.modelArray = [NSMutableArray arrayWithArray:array];
		[self  reloadTableView];
		
	}
}

- (void)dealloc
{
	[[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath withModelInfo:(NSObject *)modelInfo
{

    TopicInfo *topicInfo = (TopicInfo *)modelInfo;

    if (self.viewForSearch)
    {

		TipAbstractListViewController *abstractListViewController = [[TipAbstractListViewController alloc] initWithSlideInfo:nil];
		abstractListViewController.topicInfo = topicInfo;
		abstractListViewController.hasNavigationBar = YES;
		[abstractListViewController setNavigationTitle:topicInfo.name];
		
		[[AppDelegate rootNavigationController] pushViewController:abstractListViewController
														  animated:YES];
    }
    else
    {
        AddTitpTittleViewController *mainContentViewController = [[AddTitpTittleViewController alloc] init];
        mainContentViewController.topicInfo = topicInfo;
        mainContentViewController.hasNavigationBar = YES;
        [self.navigationController pushViewController:mainContentViewController animated:YES];

        [self.sideslipViewController closeSideBar];
    }

}
@end
